package com.bdzl.biz.controller;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdzl.pub.entity.loan.OdrFileInfoDO;
import com.bdzl.biz.service.OdrFileInfoService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 融资租赁订单合同权证信息表，主要记录订单相关的合同、权证资料文件信息
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:02:10
 */

@Controller
@RequestMapping("/bdzl/odrFileInfo")
public class OdrFileInfoController extends BaseController {
	@Autowired
	private OdrFileInfoService odrFileInfoService;

	@GetMapping()
	String OdrFileInfo(){
	    return "bdzl/odrFileInfo/odrFileInfo";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OdrFileInfoDO> odrFileInfoList = odrFileInfoService.list(query);
		int total = odrFileInfoService.count(query);
		PageUtils pageUtils = new PageUtils(odrFileInfoList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/odrFileInfo/add";
	}

	@GetMapping("/edit/{ofiId}")
	String edit(@PathVariable("ofiId") Integer ofiId,Model model){
		OdrFileInfoDO odrFileInfo = odrFileInfoService.get(ofiId);
		model.addAttribute("odrFileInfo", odrFileInfo);
	    return "bdzl/odrFileInfo/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( OdrFileInfoDO odrFileInfo){
		if(odrFileInfoService.save(odrFileInfo)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( OdrFileInfoDO odrFileInfo){
		odrFileInfoService.update(odrFileInfo);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer ofiId){
		if(odrFileInfoService.remove(ofiId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] ofiIds){
		odrFileInfoService.batchRemove(ofiIds);
		return R.ok();
	}

}
